﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="/assets/module/admin.css?v=318">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link href="/assets/module/opTable/opTable.css" rel="stylesheet" />
</head>
<body>
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">表名称:</label>
                            <div class="layui-input-inline">
                                <input name="TableName" class="layui-input" placeholder="输入名称" />
                            </div>
                        </div>

                        <div class="layui-inline">
                            &nbsp;&emsp;
                            <button class="layui-btn icon-btn" lay-filter="datetableTbSearch" lay-submit>
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                </form>
                <table id="DatetableTable" lay-filter="DatetableTable"></table>
            </div>
        </div>
    </div>

    <!-- js部分 -->
    <script src="/assets/libs/jquery/jquery-3.2.1.min.js"></script>
    <script src="/assets/libs/layui/layui.js"></script>
    <script src="/assets/js/utils.js"></script>
    <script src="/assets/js/main.js"></script>
    <script>
        layui.use(['layer', 'form', 'table', 'util', 'opTable', 'admin', 'setter'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var util = layui.util;
            var opTable = layui.opTable;
            var admin = layui.admin;
            var setter = layui.setter;

            layuiTableSet();

            /* 渲染表格 */
            var opTable = opTable.render({
                elem: '#DatetableTable',
                url: setter.baseServer + '/SystemManage/Database/GetTablePageListJson',
                page: true,
                cellMinWidth: 100,
                cols: [[
                    { field: 'TableName', title: '表名称', sort: true },
                    { field: 'TableKeyName', title: '主键名称' },
                    { field: 'TableKey', title: '主键字段' },
                    { field: 'TableCount', title: '记录数' },
                    { field: 'Remark', title: '备注' }
                ]],
                openTable: function (itemData) {

                    return {
                        // 由于同时支持展开多个表格 组装唯一的id
                        elem: '#child' + itemData.LAY_INDEX
                        , id: 'child' + itemData.LAY_INDEX
                        , url: setter.baseServer + '/SystemManage/Database/GetTableFieldListJson' + '?tableName=' + itemData.TableName
                        , page: false
                        , width: 1000
                        , headers: { 'Authorization': "Bearer " + setter.getToken().JwtToken },
                        request: {
                            pageName: 'PageIndex' //页码的参数名称，默认：page
                            , limitName: 'PageSize' //每页数据量的参数名，默认：limit
                        },
                        response: {
                            statusName: 'Tag' //规定数据状态的字段名称，默认：code
                            , statusCode: 1 //规定成功的状态码，默认：0
                            , msgName: 'Message' //规定状态信息的字段名称，默认：msg
                            , countName: 'Total' //规定数据总数的字段名称，默认：count
                            , dataName: 'Data' //规定数据列表的字段名称，默认：data
                        },
                         cols: [[
                            { field: 'TableColumn', title: '列名', width: 180, sort: true },
                            { field: 'Datatype', title: '数据类型', width: 180, sort: true },
                            { field: 'FieldLength', title: '长度', width: 180 },
                            { field: 'Remark', title: '说明' }
                        ]]
                    }
                }
                , openType: 1
            });

            /* 表格搜索 */
            form.on('submit(datetableTbSearch)', function (data) {
                opTable.reload({ where: data.field, page: { curr: 1 } });
                return false;
            });
        });
    </script>
</body>
</html>